unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, 
  Controls, Forms, Dialogs, Menus;

type
  TMainForm = class(TForm)
    mMain: TMainMenu;
    miPens: TMenuItem;
    miStyles: TMenuItem;
    miPenColors: TMenuItem;
    miPenMode: TMenuItem;

    procedure FormPaint(Sender: TObject);
    procedure OptionClick(Sender: TObject);

  private
    drawKind:integer;
    { Private declarations }

  public
    procedure SetPenDefaults;
    procedure DrawStyles;
    procedure DrawPenColors;
    procedure DrawPenMode;

    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}


procedure TMainForm.SetPenDefaults;
begin
with Canvas.Pen do
begin
Width := 1;
Mode := pmCopy;
Style := psSolid;
Color := clBlack;
end;
end;

{Phng thc nay c dung e ve ra cac net cua but ve}
procedure TMainForm.DrawStyles();
var
yPos: integer;
PenStyle: TPenStyle;

begin
drawKind:=1;
SetPenDefaults;
YPos := 20;
with Canvas do
begin
for PenStyle := psSolid to psInsideFrame do
begin
Pen.Color := clBlue;
Pen.Style := PenStyle;
MoveTo(100, yPos);
LineTo(ClientWidth, yPos);
inc(yPos, 20);              
end;
TextOut(1, 10, ' psSolid ');
TextOut(1, 30, ' psDash ');
TextOut(1, 50, ' psDot ');
TextOut(1, 70, ' psDashDot ');
TextOut(1, 90, ' psDashDotDot ');
TextOut(1, 110, ' psClear ');
TextOut(1, 130, ' psInsideFrame ');
end;
end;

procedure TMainForm.DrawPenColors();
var
i: integer;

begin
drawKind:=2;
SetPenDefaults;
with Canvas do
begin
for i := 1 to 100 do
begin
Pen.Color := RGB(Random(255),
                           Random(255), Random(255));
MoveTo(random(ClientWidth), 
                                  Random(ClientHeight));
LineTo(random(ClientWidth), 
                             Random(ClientHeight));
end
end;
end;

procedure TMainForm.DrawPenMode();
var
x,y: integer;

begin
drawKind:=3;
SetPenDefaults;
y := 10;
canvas.Pen.Width := 20;
while y < ClientHeight do
begin
canvas.MoveTo(0, y);
canvas.LineTo(ClientWidth, y);
inc(y, 30);
end;

x := 5;
canvas.pen.Mode := pmNot;
while x < ClientWidth do
begin
Canvas.MoveTo(x, 0);
canvas.LineTo(x, ClientHeight);
inc(x, 30);
end;
end;

procedure TMainForm.FormPaint(Sender: TObject);
begin
  case drawKind of
    1:DrawStyles();
    2:DrawPenColors();
    3:DrawPenMode();
  end;
end;

procedure TMainForm.OptionClick(Sender: TObject);
begin
    if sender=miStyles then drawKind:=1;
    if sender=miPenColors then drawKind:=2;
    if sender=miPenMode then drawKind:=3;
    Repaint;
end;

end.
